package cn.itcast.user.web;

import cn.itcast.user.config.MyProperties;
import cn.itcast.user.config.PatternProperties;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

/**
 * 测试使用配置文件
 * 1. 写一个普通控制器方法
 * 2. 读取配置中心的配置信息（通过属性来读取）
 */
@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope
public class UserController {

    @Autowired
    private UserService userService;

//    @Value("${pattern.dateformat}")
    private String dateformat;

    //@Autowired
    private PatternProperties patternProperties;

    //@Autowired
    private MyProperties myProperties;

//    @GetMapping("/now")
//    public String now(){
//        return patternProperties.getDateformat();
//    }
//
//    @GetMapping("/message")
//    public String message(){
//        return myProperties.getMessage();
//    }



    /**
     * 路径： /user/1
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id, HttpServletRequest request) {
        String message = request.getHeader("message");
        System.out.println(message);
        return userService.queryById(id);
    }
}
